package comm.parsers;

import java.util.ArrayList;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class NaverShortcutResultSAXParserHandler extends DefaultHandler {
	  private StringBuffer items = new StringBuffer();
	  private StringBuffer items2 = new StringBuffer();
	  private boolean isItem = false;
	  private boolean isItem2 = false;
	  
	  public int itemNum=1;
	  
	  public String link = "";
	  public String label = "";
	  
	  public String getLink(){
		  return link;
	  }	  
	  public String getLabel(){
		  return label;
	  }
	  
	  public void startElement(String uri, String localName,
	                     String qName, Attributes atts)
	  {
	      if (qName.equals("label")) {
	    	  isItem=true;  items.setLength(0); 
	      }else if (qName.equals("url")) {
	    	  isItem2=true;  items2.setLength(0); 
	      }
	  }
	  public void endElement(String uri, String localName,
	                     String qName)
	 { 
		  if (qName.equals("shortcut")){
	          label = items.toString();
	          link = items2.toString();
	          itemNum++;
	      }else if (isItem) isItem = false;
	      else if (isItem2) isItem2 = false; 
	  }
	  public void characters(char[] chars, int start, int leng) 
	  {  
	      if (isItem) {
	    	  isItem=false;  items.append(chars,start,leng);
	      }else if (isItem2) {
	    	  isItem2=false;  items2.append(chars,start,leng);
	      }
	  }
	
}
